<?php
declare (strict_types = 1);

namespace app\command\Ddhd;

use app\model\Orders;
use app\service\shopify\action\rest\OrderRest;
use statistics\OrderPrice;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;

class Shopify extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('ddhd:shopify')
            ->addArgument('action')
            ->addOption('order_id',null,Option::VALUE_OPTIONAL,'订单ID')
            ->addOption('shop_id',null,Option::VALUE_OPTIONAL,'店铺ID')
            ->setDescription('the shopify command');
    }


    //  php think ddhd:shopify  get_price_from_shopify --order_id=1 --shop_id=1
    protected function execute(Input $input, Output $output)
    {
        $action = $input->getArgument('action');
        $options = $input->getOptions();

        // 指定 订单 和  店铺时
        $order_id = $options['order_id'] ?? 0;
        $shop_id = $options['shop_id'] ?? 0;

        switch ($action)
        {
            // 更新 订单的 一个金额 （从shopify获取）
            /*
             ALTER TABLE `demo_sp1`.`ddhd_sp_orders`
ADD COLUMN `price_usd` decimal(10, 2) UNSIGNED NULL DEFAULT 0 COMMENT '销售额（美元）' AFTER `current_total_price_set`;
            ALTER TABLE `demo_sp1`.`ddhd_sp_orders`
MODIFY COLUMN `price_usd` int(10) UNSIGNED NULL DEFAULT 0 COMMENT '销售额（美元）' AFTER `current_total_price_set`;
             */
            case "get_price_from_shopify":
                $handel = new OrderPrice();
                $handel->do();
                break;

                // 测试
            case 'test':
                echo __METHOD__;exit();
                break;
        }

        // 指令输出
        $output->writeln('shopify');
    }
}
